/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.frontend.pdf;

import static java.awt.Component.CENTER_ALIGNMENT;
import java.awt.Font;
import java.text.DecimalFormat;
import javax.swing.JLabel;
import javax.swing.JPanel;
import model.Order;
import model.OrderLine;
import view.generaldesign.DesignLayout;

/**
 *
 * @author Allan
 */
public class OrderLinePanel extends JPanel
{
    private JLabel lblAmount;
    private JLabel lblDescription;
    private JLabel lblUnitPrice;
    private JLabel lblSum;
    private DecimalFormat format;
    private Order ordren;
    private OrderLine orderLine;
    
    public OrderLinePanel(Order ordren, OrderLine orderLine, int docType)
    {
        this.ordren = ordren;
        this.orderLine = orderLine;
        Font font;
        font = DesignLayout.PDF_PLAIN_10;
        format = new DecimalFormat("#,##0.00#");
        
        setLayout(null);
        setSize(510, 14); // (Width, height)
        setOpaque(false);
        
        lblAmount = new JLabel();
        lblAmount.setBounds(0, 0, 60, 14); // (X, Y, Width, Height)
        lblAmount.setFont(font);
        lblAmount.setHorizontalAlignment((int)CENTER_ALIGNMENT);
        //lblAmount.setBorder(BorderFactory.createLineBorder(new Color(0, 0, 0)));
        
        lblDescription = new JLabel();
        lblDescription.setBounds(62, 0, 265, 14);
        lblDescription.setFont(font);
        //lblDescription.setBorder(BorderFactory.createLineBorder(new Color(0, 0, 0)));
        
        lblUnitPrice = new JLabel();
        lblUnitPrice.setBounds(332, 0, 65, 14);
        lblUnitPrice.setFont(font);
        lblUnitPrice.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        //lblUnitPrice.setBorder(BorderFactory.createLineBorder(new Color(0, 0, 0)));

        lblSum = new JLabel();
        lblSum.setBounds(401, 0, 105, 14);
        lblSum.setFont(font);
        lblSum.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        //lblSum.setBorder(BorderFactory.createLineBorder(new Color(0, 0, 0)));
        
        add(lblAmount);
        add(lblDescription);
        add(lblUnitPrice);
        add(lblSum);
        
        setData(docType);
    }
    
    private void setData(int docType)
    {
        switch(docType)
        {
            case 1:
                // Ordreseddel
                lblAmount.setText("" + orderLine.getAmount());
                lblDescription.setText(orderLine.getProduct().getName());
                lblUnitPrice.setText(format.format(orderLine.getUnitPrice()) + " ");
                lblSum.setText(format.format(orderLine.getAmount() * orderLine.getUnitPrice()) + " ");
                break;
            case 2:
                // Arbejdsseddel
                lblAmount.setText("" + orderLine.getAmount());
                lblDescription.setText(orderLine.getProduct().getName());
                break;
            case 3:
                // Faktura
                lblAmount.setText("" + orderLine.getAmount());
                lblDescription.setText(orderLine.getProduct().getName());
                lblUnitPrice.setText(format.format(orderLine.getUnitPrice()) + " ");
                lblSum.setText(format.format(orderLine.getAmount() * orderLine.getUnitPrice()) + " ");
                break;
            case 4:
                // Provision
                lblAmount.setText("" + format.format(ordren.getTombStone().getCommision() / 100));
                lblDescription.setText("Tilgodehavende vedr. ordrenr. " + ordren.getId());
                lblUnitPrice.setText(format.format(ordren.totalPrice()) + " ");
                lblSum.setText(format.format((ordren.getTombStone().getCommision() / 100) * ordren.totalPrice()) + " ");
                break;
            case 5:
                // Kontoudtog linje 1
                lblAmount.setText("1");
                lblDescription.setText("Ordrenr. " + ordren.getId());
                lblUnitPrice.setText(format.format(ordren.totalPrice()) + " ");
                lblSum.setText(format.format(ordren.totalPrice()) + " ");
                break;
            case 6:
                // Kontoudtog linje 2
                lblAmount.setText("1");
                lblDescription.setText("Provision nr. " + ordren.getTombStone().getMorticianCommissionNo());
                lblUnitPrice.setText(format.format(((ordren.getTombStone().getCommision() / 100) * ordren.totalPrice()) * -1) + " ");
                lblSum.setText(format.format(((ordren.getTombStone().getCommision() / 100) * ordren.totalPrice()) * -1) + " ");
                break;
        }
    }
}
